home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / turbotut.arc / AMORT5.PAS < prev    next >
Pascal/Delphi Source File  |  1989-06-30  |  4KB  |  113 lines

  1. PROGRAM amortization_table;
  2.  
  3. VAR month                 : 1..12;
  4.     starting_month        : 1..12;
  5.     balance               : REAL;
  6.     payment               : REAL;
  7.     interest_rate         : REAL;
  8.     annual_accum_interest : REAL;
  9.     year                  : INTEGER;
  10.     number_of_years       : INTEGER;
  11.     original_loan         : REAL;
  12.  
  13.  
  14. PROCEDURE calculate_payment; (* ***************** calculate payment *)
  15. VAR temp  : REAL;
  16.     index : INTEGER;
  17. BEGIN
  18.   temp := 1.0;
  19.   FOR index := 1 TO 12*number_of_years DO
  20.     temp := temp * (1.0 + interest_rate);
  21.   payment := original_loan*interest_rate/(1.0 - 1.0/temp);
  22. END;
  23.  
  24. PROCEDURE initialize_data; (* ********************* initialize data *)
  25. BEGIN
  26.   WRITELN('   Pascal amortization program');
  27.   WRITELN;
  28.   WRITE('Enter amount borrowed                         ');
  29.   READLN(original_loan);
  30.     balance := original_loan;
  31.   WRITE('Enter interest rate as percentage (i.e. 13.5) ');
  32.   READLN(interest_rate);
  33.     interest_rate := interest_rate/1200.0;
  34.   WRITE('Enter number of years of payoff               ');
  35.   READLN(number_of_years);
  36.   WRITE('Enter month of first payment (i.e. 5 for May) ');
  37.   READLN(starting_month);
  38.   WRITE('Enter year of first payment (i.e. 1985)       ');
  39.   READLN(year);
  40.     calculate_payment;
  41.   annual_accum_interest := 0.0;  (* This is to accumulate Interest *)
  42. END;
  43.  
  44. PROCEDURE print_annual_header; (* ************** print annual header *)
  45. BEGIN
  46.   WRITELN;
  47.   WRITELN;
  48.   WRITELN('Original loan amount = ',original_loan:10:2,
  49.           '   Interest rate = ',1200.0*interest_rate:6:2,'%');
  50.   WRITELN;
  51.   WRITELN('Month    payment  interest    princ   balance');
  52.   WRITELN;
  53.   WRITELN(lst);
  54.   WRITELN(lst);
  55.   WRITELN(lst,'Original loan amount = ',original_loan:10:2,
  56.           '   Interest rate = ',1200.0*interest_rate:6:2,'%');
  57.   WRITELN(lst);
  58.   WRITELN(lst,'Month    payment  interest    princ   balance');
  59.   WRITELN(lst);
  60. END;
  61.  
  62. PROCEDURE calculate_and_print; (* ************** calculate and print *)
  63. VAR interest_payment : REAL;
  64.     principal_payment : REAL;
  65. BEGIN
  66.   IF balance > 0.0 THEN
  67.   BEGIN
  68.     interest_payment := interest_rate * balance;
  69.     principal_payment := payment - interest_payment;
  70.     IF principal_payment > balance THEN
  71.     BEGIN  (* loan payed off this month *)
  72.       principal_payment := balance;
  73.       payment := principal_payment + interest_payment;
  74.       balance := 0.0;
  75.     END
  76.     ELSE
  77.     BEGIN  (* regular monthly payment *)
  78.       balance := balance - principal_payment;
  79.     END;
  80.     annual_accum_interest := annual_accum_interest + interest_payment;
  81.     WRITELN(month:5,payment:10:2,interest_payment:10:2,
  82.             principal_payment:10:2,balance:10:2);
  83.     WRITELN(lst,month:5,payment:10:2,interest_payment:10:2,
  84.             principal_payment:10:2,balance:10:2);
  85.   END; (* of IF balance > 0.0 THEN *)
  86. END;
  87.  
  88. PROCEDURE print_annual_summary; (* ************ print annual summary *)
  89. BEGIN
  90.   WRITELN;
  91.   WRITELN('Total interest for ',year:5,' = ',
  92.            annual_accum_interest:10:2);
  93.   WRITELN;
  94.   WRITELN(lst);
  95.   WRITELN(lst,'Total interest for ',year:5,' = ',
  96.            annual_accum_interest:10:2);
  97.   annual_accum_interest := 0.0;
  98.   year := year + 1;
  99.   WRITELN(lst);
  100. END;
  101.  
  102. BEGIN   (* ********************************************* main program *)
  103.   initialize_data;
  104.   REPEAT
  105.     print_annual_header;
  106.     FOR month := starting_month TO 12 DO
  107.     BEGIN
  108.       calculate_and_print;
  109.     END;
  110.     print_annual_summary;
  111.     starting_month := 1;
  112.   UNTIL balance <= 0.0;
  113. END. (* of main program *)